package com.atguigu.thymeleaf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;


//@RestController //返回json
@Controller  //页面跳转
public class HelloController {
    @GetMapping("/hello")
    public String  hello(HttpServletRequest request,
                         HttpSession session,
                         Model model,
                         Map map,
                         ModelMap modelMap){
        //model，map，modelMap是什么？  底层都是一个  BindingAwareModelMap，最终都放在ModelAndView里面
        model.addAttribute("model_val","Model_6666");
        map.put("map_val","map_666");
        modelMap.addAttribute("modelMap_val","modelMap_6666");
        request.setAttribute("request_val","request_666");
        //他们都等于请求域,


        //thymeleaf 默认会在  类路径下的 templates 文件夹下找
        //自动配置好了thymeleaf的视图解析器  prefix   suffix
        /**
         * spring.thymeleaf.prefix=classpath:/templates/
         * spring.thymeleaf.suffix=.html
         */
        //四大域对象：    解决数据共享问题
        // page：    页面前面放的后面能取出来
        // request： 一次请求期间都能在后面取出来
        // session： 同一次会话放的数据在，其他地方都能取出来
        // application： 当前应用放的东西，所有地方，所有会话都取得出来
        request.setAttribute("userName","张三");
        request.setAttribute("h1Id", UUID.randomUUID().toString().substring(0,4));
        request.setAttribute("mycolor","color:blue");

        List<String> list = Arrays.asList("郑爽", "刘德华", "张惠妹", "成龙");

        request.setAttribute("arrayList",list);

        request.setAttribute("age",18);


        session.setAttribute("hello","world");


        //不转义脚本的情况，直接在页面展示很危险
        request.setAttribute("pre_sign","<script>alert('你真6')</script>");
        return "success";   //  classpath:/templates/success.html
    }
}
